package com.zyk.leetcode;

/**
 * @author zhangsan
 * @date 2021/4/9 17:52
 */
public class M0507 {

    // https://leetcode-cn.com/problems/exchange-lcci/
    public static int exchangeBits(int num) {
        //奇数
        int odd = num & 0x55555555;
        //偶数
        int even = num & 0xaaaaaaaa;
        odd = odd << 1;
        even = even >>> 1;
        return odd | even;
    }

    // for test
    public static void main(String[] args) {
        int num = Integer.MAX_VALUE;
        System.out.println(0x55555555);
        System.out.println(0xaaaaaaaa);
        // 奇数位上的1
        System.out.println(num & 0x55555555);
        // 偶数位上的1
        System.out.println(num & 0xaaaaaaaa);

    }

}
